package io.mft.commons.multithreading.worker;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * 工作队列
 * @描述: 
 * @版权: Copyright (c) 2015 
 * @公司: 思迪科技 
 * @作者:胡常建
 * @版本: 1.0 
 * @创建日期: 2015年5月17日 
 * @创建时间: 上午10:40:10
 */
public class WorkQueue {
	private BlockingQueue<Work> works;
	static Logger logger=LoggerFactory.getLogger(WorkQueue.class);
	public  WorkQueue(int size) {
		works = new LinkedBlockingQueue<Work>(size);
	}
	public  WorkQueue() {
		works = new LinkedBlockingQueue<Work>();
	}
	public boolean add(Work work) {
		try {
			works.put(work);
			return true;
		} catch (InterruptedException e) {
			logger.error("", e);
			return false;
		}
	}
	public Work take() throws InterruptedException {
		return works.take();
	}
	public int length() {
		return works.size();
	}
}
